/**
 * 表格时间格式化
 */
export function formatDate(cellValue) {
  if (cellValue == null || cellValue == "") return "";
  const date = new Date(cellValue)
  const year = date.getFullYear()
  const month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
  const day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
  const hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
  const minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
  const seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
}

/**
 * 时间 今天 昨天 更早
 * */
export function formatDateDay(date) {
  if (!date) return ''
  const now = new Date()
  const todayTimeStamp = now.setHours(0, 0, 0, 0)
  const targetTiemStamp = new Date(date).setHours(0, 0, 0, 0)
  const diff = todayTimeStamp - targetTiemStamp
  if (diff < 24 * 60 * 60 * 1000) return '今天'
  if (diff < 24 * 60 * 60 * 1000 * 2) return '昨天'
  return '更早'
}

/**
 * 将数组arr 按num大小分组
 * */ 
export function groupArrayBySize(arr, num) {
  var result = [];
  for (var i = 0; i < arr.length; i += num) {
    result.push(arr.slice(i, i + num));
  }
  return result;
}

/***
 * 格式化query to object
 * */ 

export function formatQuery2Obj(str){
  let arr = str.split('&')
  let res = {}
  for(let i =0;i<arr.length;i++){
    let [key,value] = arr[i].split("=");
    // value = decodeURIComponent(value)
    //如果参数已经有了，则进行追加
    res[key] = value

  }
  return res
}